package com.xyz.wll.es.manager.ui.model;

import javax.swing.table.DefaultTableModel;
import java.util.Vector;

public class AppendableTableModel extends DefaultTableModel {
    Vector<Boolean> editableRows;

    public AppendableTableModel(Object[][] datas, Object[] columns) {
        super(datas, columns);
        editableRows = new Vector<>(datas.length);
        for(int i=0; i<datas.length; i++) {
            editableRows.add(false);
        }
    }

    @Override
    public boolean isCellEditable(int row, int column) {
        return editableRows.get(row);
    }

    @Override
    public void insertRow(int row, Vector rowData) {
        super.insertRow(row, rowData);
        editableRows.insertElementAt(true, row);
    }

    @Override
    public void removeRow(int row) {
        if(editableRows.get(row)) {
            super.removeRow(row);
            editableRows.remove(row);
        } else {
            System.out.println(String.format("第%d行不是新增行,不能编辑！！！", row));
        }
    }
}
